import java.util.*;

public class DemoBook {
    public static void main(String[] args) {
        var library = new HashMap<String, Book>();
        List<Book> books = new ArrayList<Book>();
        int n = 0;
        Scanner input = new Scanner(System.in);
        System.out.println("输入存放书籍数：");
        n = input.nextInt();
        for (int i = 0; i < n; i++) {
            Book book = new Book();
            System.out.println("输入图书编号：");
            String id = input.next();
            book.setId(id);
            System.out.println("输入名称：");
            String name = input.next();
            book.setName(name);
            System.out.println("输入价格：");
            int price = input.nextInt();
            book.setPrice(price);
            System.out.println("输入出版社：");
            String place = input.next();
            book.setPlace(place);

            books.add(book);
            library.put(id, book);
        }

        System.out.println("---链表遍历图书信息：");
        for (int i = 0; i < n; i++) {
            Book book = books.get(i);
            System.out.println("编号：" + book.getId() + " 名称：" + book.getName() + " 价格" + book.getPrice() + " 出版社" + book.getPlace());
        }
        System.out.println();
        System.out.println("---映射遍历图书信息：");
        Iterator iter = library.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            Book book = (Book) entry.getValue();
            System.out.println("编号：" + entry.getKey() + " 名称：" + book.getName() + " 价格" + book.getPrice() + " 出版社" + book.getPlace());
        }

    }

}
